﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> 
<%@ taglib prefix="d" uri="/WEB-INF/resource.tld" %>

<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<sec:authentication property="principal" var="currentPrincipal" scope="page" />

<fmt:setBundle basename="ApplicationMessage" />
<fmt:setLocale value="zh_CN" />
<!DOCTYPE html>
<html lang="zh-CN">
<head>

  <%@ include file="/WEB-INF/include/meta.jsp"%>
  <%@ include file="/WEB-INF/include/css.jsp"%>
  
</head>

<body>

  <%@ include file="/WEB-INF/include/header.jsp"%>
  
  <%@ include file="/WEB-INF/include/menu.jsp"%>

  <div class="container main-content">

    <div class="panel panel-default x-panel x-panel-layout">

      <div class="panel-heading">
        <ol class="breadcrumb">
          <li><a href="${ctx.host}/ecommerce">电商管理</a></li>
          <li class="active">课程排期</li>
        </ol>
      </div>

      <div class="panel-body">

        <div class="col-xs-2 x-panel-layout-left no-horizontal-padding">
          <%@ include file="/WEB-INF/include/submenu.jsp"%>
        </div>

        <div class="col-xs-10 x-panel-layout-right">

          <div class="x-breadcrumb-wrapper">
            <div class="x-breadcrumb clearfix">
              <h2><i class="glyphicon glyphicon-fire" title=""></i>&nbsp;&nbsp;<span>月卡季卡课程课程&nbsp;-&nbsp;月卡季卡课程</span></h2>
              <div class="pull-right">
                <c:choose>
                  <c:when test="${not empty currentPrincipal.site}">
                    <span class="current-branchCode">${currentPrincipal.site.name}</span>
                  </c:when>
                  <c:otherwise>
                    <select name="site">
                      <option value="">所有门店</option>
                      <c:forEach var="site" items="${persist.getSites(currentPrincipal.id)}">
                        <option value="${site.id}" ${site.id == param.site ? 'selected' : ''}>${site.name}</option>
                      </c:forEach>
                    </select>
                  </c:otherwise>
                </c:choose>
              </div>
            </div>
            <div class="x-breadcrumb-wrapper top-margin-20" style="position: relative;margin-top: 15px;">
              <ul class="nav nav-pills x-breadcrumb-nav">
                <c:forEach var="roundStatus" items="${enums['roundStatus']}">
                  <li class="pull-left ${status == roundStatus.alias ? 'active' : ''}"><a href="${ctx.host}/year-rounds?status=${roundStatus.alias}&site=${param.site}">${roundStatus.description}</a></li>
                </c:forEach>
              </ul>
            </div>
            
            <div class="x-breadcrumb-wrapper clearfix" style="position: relative; margin-top: 15px;">
              <div class="btn-group pull-right">
                <a href="${ctx.host}/year-rounds/search?site=${not empty site ? site : ''}${not empty queryString ? '&'.concat(queryString) : ''}" data-target="#" data-toggle="modal" class="btn btn-default x-btn btn-shadow btn-shadow-default">
                  <i class="glyphicon glyphicon-search"></i>&nbsp;&nbsp;过滤查询
                </a>
              </div>
            </div>
          </div>
          
          <table class="table table-striped table-hover x-table" style="margin-bottom:20px;">
            <thead>
              <tr>
                <th>课程名称</th>
                <th>学员名称</th>
                <th>学员手机</th>
                <th>课件属性</th>
                <th>启用/冻结-解冻/有效</th>
                <th>已上课时</th>
                <th>已/可冻结次数</th>
                <th>状态</th>
                <th class="text-center">操作</th>
              </tr>
            </thead>
            <tbody>
              <c:forEach var="courseRound" items="${courseRounds}">
                <tr>
                  <td>${courseRound.course.name}</td>
                  <td>${courseRound.student.name}</td>
                  <td>${courseRound.student.mobile}</td>
                  <td><p>${courseRound.fitnessGroup.name}</p>
                      <p><c:if test="${not empty courseRound.student.tagIds}"><c:forEach var="tag" items="${persist.coursewareTags(courseRound.student.arrayTagIds)}">${tag.name}&nbsp;&nbsp;</c:forEach></c:if></p>
                  </td>
                  <td>
                    
                    <c:choose>
                      <c:when test="${courseRound.effectiveStart == null}">
                        未开启<br/>
                      </c:when>
                      <c:otherwise>
                        <fmt:formatDate value="${courseRound.effectiveStart}" pattern="yyyy-MM-dd"/><br/>
                      </c:otherwise>
                    </c:choose>
                    <c:choose>
                      <c:when test="${courseRound.holdDate != null and courseRound.courseStatus.hold}">
                        <fmt:formatDate value="${courseRound.holdDate}" pattern="yyyy-MM-dd"/>${empty courseRound.holdEndDate ? '<br/>' : ''}
                        <c:if test="${not empty courseRound.holdEndDate}">
                          &nbsp;&nbsp;-&nbsp;&nbsp;<fmt:formatDate value="${courseRound.holdEndDate}" pattern="yyyy-MM-dd"/><br/>
                        </c:if>
                      </c:when>
                      <c:otherwise>
                        未冻结<br/>
                      </c:otherwise>
                    </c:choose>
                    <fmt:formatDate value="${courseRound.effectiveEndTime}" pattern="yyyy-MM-dd"/>
                  </td>
                  <td>${courseRound.finished}</td>
                  <td>${courseRound.freezedNumber}/${courseRound.course.freezingNumber}</td>
                  <td>${courseRound.courseStatus.description}</td>
                  
                  <td class="text-center">
                    <c:if test="${not currentPrincipal.coursewareMonitor}">
                      <c:if test="${not empty courseRound.coach and empty courseRound.fitnessGroup}">
                        <a href="${ctx.host}/year-rounds/${courseRound.id}/change-group" data-toggle="modal" data-target="#change-group">分组</a>&nbsp;&nbsp;
                      </c:if>
                      <c:if test="${not empty courseRound.fitnessGroup}">
                        <a href="${ctx.host}/year-rounds/${courseRound.id}/edit-group" data-toggle="modal" data-target="#edit-group">修改分组</a>&nbsp;&nbsp;
                      </c:if>
                      <c:if test="${not empty courseRound.fitnessGroup}">
                        <a href="${ctx.host}/year-rounds/${courseRound.id}/edit-tag" data-toggle="modal" data-target="#tag">修改标签</a>&nbsp;&nbsp;
                      </c:if>
                      <c:if test="${!currentPrincipal.coursewareManager and courseRound.courseStatus.prepare}">
                        <c:if test="${empty courseRound.coach}">
                          <a href="${ctx.host}/year-rounds/${courseRound.id}/arrange-coach" data-toggle="modal" data-target="#arrange-coach">指定主教练</a>&nbsp;&nbsp;
                        </c:if>
                        <c:if test="${not empty courseRound.coach}">
                          <a href="${ctx.host}/year-rounds/${courseRound.id}/change-coach" data-toggle="modal" data-target="#change-coach">更改主教练</a>&nbsp;&nbsp;
                        </c:if>
                      </c:if>
                      <c:if test="${!currentPrincipal.coursewareManager and courseRound.courseStatus.ready}">
                        <a href="${ctx.host}/year-rounds/${courseRound.id}/change-coach" data-toggle="modal" data-target="#change-coach">更改主教练</a>&nbsp;&nbsp; 
                      </c:if>
                      <c:if test="${!currentPrincipal.coursewareManager and courseRound.courseStatus.ready}">
                        <c:choose>
                          <c:when test="${courseRound.freezedNumber >= courseRound.course.freezingNumber}">
                            冻结已用
                          </c:when>
                          <c:otherwise>
                            <c:if test="${!currentPrincipal.areaServer and !currentPrincipal.siteServer and not empty courseRound.effectiveStart}">
                              <a href="${ctx.host}/year-rounds/${courseRound.id}/toggle-freeze" data-toggle="modal" data-target="#toggle-freeze">冻结</a>&nbsp;&nbsp;
                            </c:if>
                          </c:otherwise>
                        </c:choose>
                      </c:if>
                      <c:if test="${!currentPrincipal.coursewareManager and courseRound.courseStatus.hold}">
                        <c:choose>
                          <c:when test="${courseRound.freezedNumber > courseRound.course.freezingNumber}">
                            无法解冻
                          </c:when>
                          <c:otherwise>
                            <a href="${ctx.host}/year-rounds/${courseRound.id}/toggle-freeze" data-toggle="modal" data-target="#toggle-freeze">解冻</a>&nbsp;&nbsp;
                          </c:otherwise>
                        </c:choose>
                      </c:if> 
                      <c:if test="${!currentPrincipal.coursewareManager}">
                        <c:if test="${(courseRound.courseStatus.ready or courseRound.courseStatus.expire) and !currentPrincipal.areaServer and !currentPrincipal.siteServer}">
                          <a href="${ctx.host}/year-rounds/${courseRound.id}/stop-camp" data-toggle="modal" data-target="#stop-camp">手动结营</a>
                        </c:if>
                        <%-- <c:if test="${currentPrincipal.root || currentPrincipal.admin || currentPrincipal.areaServer}"> --%>
                        <c:if test="${currentPrincipal.root || currentPrincipal.admin || currentPrincipal.specialSite}">
                          <c:if test="${courseRound.courseStatus.ready || courseRound.courseStatus.expire}">
                            <a href="${ctx.host}/year-rounds/${courseRound.id}/delay" data-toggle="modal" data-target="#round-delay">延期</a>
                          </c:if>
                        </c:if>
                        <c:if test="${courseRound.courseStatus.activate}">
                          <a href="${ctx.host}/year-rounds/${courseRound.id}/activate" data-toggle="modal" data-target="#round-activate">激活</a>
                        </c:if>
                      </c:if>
                    </c:if>
                    <c:if test="${currentPrincipal.root or currentPrincipal.admin}">
                      <c:if test="${courseRound.couldChangeSite()}">
                        <a href="${ctx.host}/year-rounds/${courseRound.id}/change-site" data-toggle="modal" data-target="#round-change-site">转店</a>
                      </c:if>
                    </c:if>
                    <c:if test="${currentPrincipal.root or currentPrincipal.admin}">
                      <c:if test="${status == 'ready' and courseRound.dishonesty}">
                        <a href="${ctx.host}/year-rounds/${courseRound.id}/honesty" data-toggle="modal" data-target="#honesty">失信恢复</a>
                      </c:if>
                    </c:if>
                    <a href="${ctx.host}/year-rounds/${courseRound.id}">详情</a>
                  </td>
                  
                </tr>
              </c:forEach>
            </tbody>
          </table>

          <jsp:include page="/WEB-INF/include/page.jsp">
            <jsp:param name="url" value="year-rounds" />
            <jsp:param name="queryString" value="${queryString}" />
          </jsp:include>

        </div>
      </div>
    </div>
  </div>

  <%@ include file="/WEB-INF/include/script.jsp"%>
  <d:resource root="${ctx.resource}/build" type="script" src="js/page/course/year-round-list.js">
    <script type="text/javascript">
      require(['page/course/year-round-list'], function(page) {
        page.init({status: '${status}'})
      })
    </script>
  </d:resource>
</body>

</html>
